package com.jqr.activity.myschool.https

import android.content.Context
import androidx.room.Dao
import androidx.room.Database
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Room
import androidx.room.RoomDatabase
import com.jqr.activity.myschool.https.models.ArticleNoContent
@Dao
interface  ArticleDao{
    @Query("select * from articlenocontent")
   suspend fun  getAll():List<ArticleNoContent>
    @Insert
   suspend fun  insertAll(articles:List<ArticleNoContent>);
    @Query("delete from articlenocontent")
  suspend  fun  deleteAll()
}
@Database(entities = [ArticleNoContent::class], version = 1, exportSchema = false)
abstract class AppDatabase:RoomDatabase(){

    abstract  fun articleDao():ArticleDao

    companion object{

        private var instance:AppDatabase?=null

        private  const val DATABASE_NAME="school.db"

        fun  getInstance(context: Context):AppDatabase{

           return instance?:Room.databaseBuilder(context,AppDatabase::class.java, DATABASE_NAME)
                .build().also { instance=it }
        }
    }

}